-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invert the binding order of InitializerExpressions and CreationExpressions #30805
Conversation
…pressions: - Push intializer binding into the respective creation expression bindings so that initializer binding takes place *after* the creation, ensuring any referenced out vars have already been inferred, preventing infinite loops - Add test to show behavior
} | ||
} | ||
"; | ||
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the CreateCompilation
helper. It's the standard helper we should be using whenever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@" | ||
public class C | ||
{ | ||
public int Number{ get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space before brace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -34493,6 +34493,32 @@ public class C | |||
"); | |||
Assert.Null(model.GetOperation(node3).Parent); | |||
} | |||
|
|||
[Fact] | |||
public void OutVarInConstructorUsedInInitializer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a similar test for collection initializers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added OutVarInConstructorUsedInCollectionInitializer
} | ||
finally | ||
{ | ||
analyzedArguments.Free(); | ||
} | ||
} | ||
|
||
private BoundExpression MakeBadExpressionForObjectCreation(ObjectCreationExpressionSyntax node, TypeSymbol type, BoundExpression boundInitializerOpt, AnalyzedArguments analyzedArguments) | ||
private BoundExpression MakeBadExpressionForObjectCreation(ObjectCreationExpressionSyntax node, TypeSymbol type, AnalyzedArguments analyzedArguments, DiagnosticBag diagnostics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case node.Initializer is null
the diagnostics
parameter won't be used. Should we assert that it's empty in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that it will definitely be empty... It gets passed in from much higher up the stack. All we know is that we wouldn't add anything to it, but the code is simple enough that it seems trivially obvious we haven't changed it in the non-initializer case?
|
||
BoundObjectInitializerExpressionBase makeBoundInitializerOpt() | ||
{ | ||
if (initializerSyntaxOpt != null ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space before close paren
Close / re-open to trigger CI |
- Add a colleciton initializer test - Fix whitespace nits
} | ||
"; | ||
var compilation = CreateCompilation(source, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular); | ||
CompileAndVerify(compilation, expectedOutput: @"1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you could just use CompileAndVerify
. Not blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this was just copy/paste from the other tests. Cleaned up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 4)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…out-if-error-message * origin/master: (1712 commits) User-defined operator checks should ignore differences in tuple member names (dotnet#30774) Attempted fix for correctly reporting error CS1069 when using implicit namespaces (dotnet#30244) Invert the binding order of InitializerExpressions and CreationExpressions (dotnet#30805) Use Arcade bootstrapping scripts (dotnet#30498) Ensure that the compilers produce double.NaN values in IEEE canonical form. (dotnet#30587) Remove properties set in BeforeCommonTargets.targets Fix publishing of dependent projects Contributing page: reference Unix build instructions Delete 0 Propagate values from AbstractProject to VisualStudioProjectCreationInfo Fix publishing nuget info of dev16.0.x-vs-deps branch Revert "Add a SetProperty API for CPS to passing msbuild properties" Validate generic arguments in `using static` directives (dotnet#30737) Correct 15.9 publish data Enable test. Do not inject attribute types into .Net modules. Add a SetProperty API for CPS to passing msbuild properties Revert "add beta2 suffix to dev16 branch" Fix references Remove commit sha from package versions ...
Fixes #30357